package com.tenement.controller;

import com.tenement.common.Axios;
import com.tenement.entity.Suggest;
import com.tenement.enums.RespBusiness;
import com.tenement.service.SuggestService;
import com.tenement.vo.QueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 *  控制层。
 *
 * @author BertXie
 * @since 1.0.1
 */
@RestController
@RequestMapping("/suggest")
@RequiredArgsConstructor
@Api(tags = "建议管理接口")
public class SuggestController {


    private final SuggestService suggestService;

    @ApiOperation(value = "操作建议数据")
    @PutMapping("operator")
    public Axios operator(Suggest suggest)
    {
        return suggestService.saveOrUpdate(suggest) ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.FAIL);
    }

    @ApiOperation(value = "回馈建议")
    @PutMapping("feedback")
    public Axios feedback(Suggest suggest)
    {
        return suggestService.feedback(suggest) ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.FAIL);
    }

    @ApiOperation(value = "获取建议数据列表")
    @PostMapping("list")
    public Axios list(@RequestBody QueryVo queryVo)
    {
        return Axios.success(suggestService.list(queryVo));
    }


    @ApiOperation(value = "删除建议数据")
    @DeleteMapping("remove/{id}")
    public Axios remove(@PathVariable Long id)
    {
        return suggestService.removeById(id) ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.FAIL);
    }


}
